﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace PLCS.App.Shared.Converts
{
    public class EnumToIntConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // 将枚举值转换为整数值
            if (value != null && value is Enum)
            {
                return (int)value;
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // 将整数值转换为枚举值
            if (value != null && value is int)
            {
                return Enum.ToObject(targetType, value);
            }
            return null;
        }
    }
}